package chapter4.No4_1_使用reentrantLock类.demo17;

import java.util.Calendar;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by Administrator on 2016/11/22.
 */
public class ServiceClass {
    ReentrantLock lock = new ReentrantLock();
    Condition condition = lock.newCondition();

    public void waitMethod() {
        lock.lock();
        System.out.println("进入wait:"+System.currentTimeMillis());
        Calendar c = Calendar.getInstance();
        c.add(Calendar.SECOND, 10);
        try {
            condition.awaitUntil(c.getTime());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("退出wait:"+System.currentTimeMillis());
        lock.unlock();
    }

    public void signalMethod() {
        lock.lock();
        condition.signal();
        lock.unlock();
    }
}
